package struts2.action;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import Controller.ConnectDB;
import DAO.ConDB;
import DAO.Dao_addService;
import DAO.ServiceReferenceDAO;
import Entity.Checkbox;
import Entity.Funding;
import Entity.Reference;
import Entity.ReferenceData;
import Entity.Services;
import EntityBean.Organization;
import EntityBean.Premise;

import com.opensymphony.xwork2.ActionSupport;

public class DetailServiceAction extends ActionSupport {
	private ArrayList<Organization> listOrg = new ArrayList<Organization>();
	public ArrayList<Organization> getListOrg() {
		return listOrg;
	}

	public void setListOrg(ArrayList<Organization> listOrg) {
		this.listOrg = listOrg;
	}

	public ArrayList<Premise> getListPremise() {
		return listPremise;
	}

	public void setListPremise(ArrayList<Premise> listPremise) {
		this.listPremise = listPremise;
	}

	private ArrayList<Premise> listPremise = new ArrayList<Premise>();
	
	private Services sv;
	private int id;
	private String sv_name;
	private String sub_type;
	private String contacts;

	public int getServiceid() {
		return serviceid;
	}

	public void setServiceid(int serviceid) {
		this.serviceid = serviceid;
	}

	public ArrayList<Checkbox> getListCheck() {
		return listCheck;
	}

	public void setListCheck(ArrayList<Checkbox> listCheck) {
		this.listCheck = listCheck;
	}

	public ArrayList<Reference> getListR() {
		return listR;
	}

	public void setListR(ArrayList<Reference> listR) {
		this.listR = listR;
	}

	private String serviceDescription;
	private String client_des;
	private String sv_attenace;
	private String sv_start_expect;
	private String sv_start;
	private String sv_end;
	private int sv_ed_year;
	private int sv_ed_month;
	private boolean active;
	private String sv_full_des;
	private String dept_code;
	private String sv_type;
	private String sv_des_delivery;
	private String sv_contract_code;
	private String sv_contract_value;
	private boolean contract_state;
	private String method;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSub_type() {
		return sub_type;
	}

	public void setSub_type(String sub_type) {
		this.sub_type = sub_type;
	}

	public String getContacts() {
		return contacts;
	}

	public void setContacts(String contacts) {
		this.contacts = contacts;
	}

	public String getServiceDescription() {
		return serviceDescription;
	}

	public void setServiceDescription(String serviceDescription) {
		this.serviceDescription = serviceDescription;
	}

	public String getClient_des() {
		return client_des;
	}

	public void setClient_des(String client_des) {
		this.client_des = client_des;
	}

	public String getSv_attenace() {
		return sv_attenace;
	}

	public void setSv_attenace(String sv_attenace) {
		this.sv_attenace = sv_attenace;
	}

	public String getSv_start_expect() {
		return sv_start_expect;
	}

	public void setSv_start_expect(String sv_start_expect) {
		this.sv_start_expect = sv_start_expect;
	}

	public String getSv_start() {
		return sv_start;
	}

	public void setSv_start(String sv_start) {
		this.sv_start = sv_start;
	}

	public String getSv_end() {
		return sv_end;
	}

	public void setSv_end(String sv_end) {
		this.sv_end = sv_end;
	}

	public int getSv_ed_year() {
		return sv_ed_year;
	}

	public void setSv_ed_year(int sv_ed_year) {
		this.sv_ed_year = sv_ed_year;
	}

	public int getSv_ed_month() {
		return sv_ed_month;
	}

	public void setSv_ed_month(int sv_ed_month) {
		this.sv_ed_month = sv_ed_month;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public String getSv_full_des() {
		return sv_full_des;
	}

	public void setSv_full_des(String sv_full_des) {
		this.sv_full_des = sv_full_des;
	}

	public String getDept_code() {
		return dept_code;
	}

	public void setDept_code(String dept_code) {
		this.dept_code = dept_code;
	}

	public String getSv_type() {
		return sv_type;
	}

	public void setSv_type(String sv_type) {
		this.sv_type = sv_type;
	}

	public String getSv_des_delivery() {
		return sv_des_delivery;
	}

	public void setSv_des_delivery(String sv_des_delivery) {
		this.sv_des_delivery = sv_des_delivery;
	}

	public String getSv_contract_code() {
		return sv_contract_code;
	}

	public void setSv_contract_code(String sv_contract_code) {
		this.sv_contract_code = sv_contract_code;
	}

	public String getSv_contract_value() {
		return sv_contract_value;
	}

	public void setSv_contract_value(String sv_contract_value) {
		this.sv_contract_value = sv_contract_value;
	}

	public boolean isContract_state() {
		return contract_state;
	}

	public void setContract_state(boolean contract_state) {
		this.contract_state = contract_state;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	private ArrayList<ReferenceData> listAttend;

	public ArrayList<ReferenceData> getListAttend() {
		return listAttend;
	}

	public void setListAttend(ArrayList<ReferenceData> listAttend) {
		this.listAttend = listAttend;
	}

	public ArrayList<ReferenceData> getListServiceType() {
		return listServiceType;
	}

	public void setListServiceType(ArrayList<ReferenceData> listServiceType) {
		this.listServiceType = listServiceType;
	}

	public ArrayList<ReferenceData> getListMethod() {
		return listMethod;
	}

	public void setListMethod(ArrayList<ReferenceData> listMethod) {
		this.listMethod = listMethod;
	}

	private ArrayList<ReferenceData> listServiceType;
	private ArrayList<ReferenceData> listMethod;

	public Services getSv() {
		return sv;
	}

	public void setSv(Services sv) {
		this.sv = sv;
	}

	public String getSv_name() {
		return sv_name;
	}

	public void setSv_name(String sv_name) {
		this.sv_name = sv_name;
	}

	private String sv_ed;

	public String getSv_ed() {
		return sv_ed;
	}

	public void setSv_ed(String sv_ed) {
		this.sv_ed = sv_ed;
	}

	private String actives;

	public String getActives() {
		return actives;
	}

	public void setActives(String actives) {
		this.actives = actives;
	}

	private String sv_state;

	public String getSv_state() {
		return sv_state;
	}

	public void setSv_state(String sv_state) {
		this.sv_state = sv_state;
	}

	// Tuan
	// Tuan
	private String selectedid;

	public String getSelectedid() {
		return selectedid;
	}

	public void setSelectedid(String selectedid) {
		this.selectedid = selectedid;
	}

	private int serviceid;
	ArrayList<Checkbox> listCheck;
	ArrayList<Reference> listR;

	// Tuyen
	// Date start;
	// Date end;
	// Date requiredby;
	// Date completeddate;
	// Date donationdate;
	// java.sql.Date sqlstart;
	// java.sql.Date sqlend;
	// java.sql.Date sqlrequiredby;
	// java.sql.Date sqlcompleteddate;
	// java.sql.Date sqldonationdate;
	// private int fundingId=1;
	// private String fundingSource;
	// private String fundingContactDetails;
	// private String contact2;
	// private int fundingAmount;
	// private String fundingStart="2013-07-10";
	// private String fundingEnd="2013-07-10";
	// private String fundingNeeds;
	// private Boolean fundingContinuationNeeded;
	// private int fundingContinuationAmount=10;
	// private String fundingContinuationDetails="contact";
	// private String fundraisingForText;
	// private String fundraisingWhy;
	// private String fundraisingNeeds;
	// private String fundraisingRequiredBy="2013-07-10";
	// private Boolean fundraisingComplete;
	// private String fundraisingCompletedDate="2013-07-10";
	// private Boolean fundraisingDonorAnonymous;
	// private int fundraisingDonorAmount;
	// private String fundraisingDonationDate="2013-07-10";
	// private Boolean fundraisingDonationIncremental;
	Date start;
	Date end;
	Date requiredby;
	Date completeddate;
	Date donationdate;
	java.sql.Date sqlstart;
	java.sql.Date sqlend;
	java.sql.Date sqlrequiredby;
	java.sql.Date sqlcompleteddate;
	java.sql.Date sqldonationdate;
	private int fundingId = 1;
	private String fundingSource;
	// private String fundingContactDetails;
	private String contact2;
	private int fundingAmount;
	private String fundingStart = "2013-07-10";
	private String fundingEnd = "2013-07-10";
	private String fundingNeeds;
	private Boolean fundingContinuationNeeded;
	private int fundingContinuationAmount = 10;
	private String fundingContinuationDetails = "contact";
	private String fundraisingForText;
	private String fundraisingWhy;
	private String fundraisingNeeds;
	private String fundraisingRequiredBy = "2013-07-10";
	private Boolean fundraisingComplete;
	private String fundraisingCompletedDate = "2013-07-10";
	private Boolean fundraisingDonorAnonymous;
	private int fundraisingDonorAmount;
	private String fundraisingDonationDate = "2013-07-10";
	private Boolean fundraisingDonationIncremental;

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public Date getRequiredby() {
		return requiredby;
	}

	public void setRequiredby(Date requiredby) {
		this.requiredby = requiredby;
	}

	public Date getCompleteddate() {
		return completeddate;
	}

	public void setCompleteddate(Date completeddate) {
		this.completeddate = completeddate;
	}

	public Date getDonationdate() {
		return donationdate;
	}

	public void setDonationdate(Date donationdate) {
		this.donationdate = donationdate;
	}

	public java.sql.Date getSqlstart() {
		return sqlstart;
	}

	public void setSqlstart(java.sql.Date sqlstart) {
		this.sqlstart = sqlstart;
	}

	public java.sql.Date getSqlend() {
		return sqlend;
	}

	public void setSqlend(java.sql.Date sqlend) {
		this.sqlend = sqlend;
	}

	public java.sql.Date getSqlrequiredby() {
		return sqlrequiredby;
	}

	public void setSqlrequiredby(java.sql.Date sqlrequiredby) {
		this.sqlrequiredby = sqlrequiredby;
	}

	public java.sql.Date getSqlcompleteddate() {
		return sqlcompleteddate;
	}

	public void setSqlcompleteddate(java.sql.Date sqlcompleteddate) {
		this.sqlcompleteddate = sqlcompleteddate;
	}

	public java.sql.Date getSqldonationdate() {
		return sqldonationdate;
	}

	public void setSqldonationdate(java.sql.Date sqldonationdate) {
		this.sqldonationdate = sqldonationdate;
	}

	public int getFundingId() {
		return fundingId;
	}

	public void setFundingId(int fundingId) {
		this.fundingId = fundingId;
	}

	public String getFundingSource() {
		return fundingSource;
	}

	public void setFundingSource(String fundingSource) {
		this.fundingSource = fundingSource;
	}

	public String getContact2() {
		return contact2;
	}

	public void setContact2(String contact2) {
		this.contact2 = contact2;
	}

	public int getFundingAmount() {
		return fundingAmount;
	}

	public void setFundingAmount(int fundingAmount) {
		this.fundingAmount = fundingAmount;
	}

	public String getFundingStart() {
		return fundingStart;
	}

	public void setFundingStart(String fundingStart) {
		this.fundingStart = fundingStart;
	}

	public String getFundingEnd() {
		return fundingEnd;
	}

	public void setFundingEnd(String fundingEnd) {
		this.fundingEnd = fundingEnd;
	}

	public String getFundingNeeds() {
		return fundingNeeds;
	}

	public void setFundingNeeds(String fundingNeeds) {
		this.fundingNeeds = fundingNeeds;
	}

	public Boolean getFundingContinuationNeeded() {
		return fundingContinuationNeeded;
	}

	public void setFundingContinuationNeeded(Boolean fundingContinuationNeeded) {
		this.fundingContinuationNeeded = fundingContinuationNeeded;
	}

	public int getFundingContinuationAmount() {
		return fundingContinuationAmount;
	}

	public void setFundingContinuationAmount(int fundingContinuationAmount) {
		this.fundingContinuationAmount = fundingContinuationAmount;
	}

	public String getFundingContinuationDetails() {
		return fundingContinuationDetails;
	}

	public void setFundingContinuationDetails(String fundingContinuationDetails) {
		this.fundingContinuationDetails = fundingContinuationDetails;
	}

	public String getFundraisingForText() {
		return fundraisingForText;
	}

	public void setFundraisingForText(String fundraisingForText) {
		this.fundraisingForText = fundraisingForText;
	}

	public String getFundraisingWhy() {
		return fundraisingWhy;
	}

	public void setFundraisingWhy(String fundraisingWhy) {
		this.fundraisingWhy = fundraisingWhy;
	}

	public String getFundraisingNeeds() {
		return fundraisingNeeds;
	}

	public void setFundraisingNeeds(String fundraisingNeeds) {
		this.fundraisingNeeds = fundraisingNeeds;
	}

	public String getFundraisingRequiredBy() {
		return fundraisingRequiredBy;
	}

	public void setFundraisingRequiredBy(String fundraisingRequiredBy) {
		this.fundraisingRequiredBy = fundraisingRequiredBy;
	}

	public Boolean getFundraisingComplete() {
		return fundraisingComplete;
	}

	public void setFundraisingComplete(Boolean fundraisingComplete) {
		this.fundraisingComplete = fundraisingComplete;
	}

	public String getFundraisingCompletedDate() {
		return fundraisingCompletedDate;
	}

	public void setFundraisingCompletedDate(String fundraisingCompletedDate) {
		this.fundraisingCompletedDate = fundraisingCompletedDate;
	}

	public Boolean getFundraisingDonorAnonymous() {
		return fundraisingDonorAnonymous;
	}

	public void setFundraisingDonorAnonymous(Boolean fundraisingDonorAnonymous) {
		this.fundraisingDonorAnonymous = fundraisingDonorAnonymous;
	}

	public int getFundraisingDonorAmount() {
		return fundraisingDonorAmount;
	}

	public void setFundraisingDonorAmount(int fundraisingDonorAmount) {
		this.fundraisingDonorAmount = fundraisingDonorAmount;
	}

	public String getFundraisingDonationDate() {
		return fundraisingDonationDate;
	}

	public void setFundraisingDonationDate(String fundraisingDonationDate) {
		this.fundraisingDonationDate = fundraisingDonationDate;
	}

	public Boolean getFundraisingDonationIncremental() {
		return fundraisingDonationIncremental;
	}

	public void setFundraisingDonationIncremental(
			Boolean fundraisingDonationIncremental) {
		this.fundraisingDonationIncremental = fundraisingDonationIncremental;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub]
		System.out.println("sv :" + sv_name);
		sv = Dao_addService.getServices(sv_name);
		Dao_addService dao = new Dao_addService();
		listAttend = dao.getList("sv_att");
		listServiceType = dao.getList("sv_type");
		listMethod = dao.getList("sv_method");
		if (sv != null) {
			id = sv.getId();
			sub_type = sv.getSub_type();
			contacts = sv.getContact();
			serviceDescription = sv.getSv_description();
			System.out.println("des : " + serviceDescription);
			client_des = sv.getClient_des();
			sv_attenace = sv.getSv_attenace();
			sv_start_expect = sv.getSv_start_expect();
			sv_start = sv.getSv_start();
			sv_end = sv.getSv_end();
			sv_ed_year = sv.getSv_ed_year();
			sv_ed_month = sv.getSv_ed_month();
			if (sv_ed_month > 0 || sv_ed_year > 0)
				sv_ed = "yes";
			else
				sv_ed = "no";
			active = sv.isActive();
			if (active)
				actives = "yes";
			else
				actives = "no";
			sv_full_des = sv.getSv_full_des();
			dept_code = sv.getDept_code();
			sv_type = sv.getSv_type();
			sv_des_delivery = sv.getSv_des_delivery();
			sv_contract_code = sv.getSv_contract_code();
			sv_contract_value = sv.getSv_contract_value();
			contract_state = sv.isContract_state();
			if (contract_state)
				sv_state = "true";

			else
				sv_state = "false";
			System.out.println("state :" + sv_state);
			method = sv.getMethod();

			// Tuyen Funding
			serviceid = id;
			ConDB con = new ConDB();
			Funding funding = con.getFunding(serviceid);
			fundingSource = funding.getFundingSource();
			contact2 = funding.getContact();
			fundingAmount = funding.getFundingAmount();
			fundingNeeds = funding.getFundingNeeds();
			System.out
					.println("tuyen" + funding.getFundingContinuationNeeded());
			fundingContinuationNeeded = funding.getFundingContinuationNeeded();
			fundingContinuationAmount = funding.getFundingContinuationAmount();
			fundingContinuationDetails = funding
					.getFundingContinuationDetails();
			fundraisingForText = funding.getFundraisingForText();
			fundraisingWhy = funding.getFundraisingWhy();
			fundraisingNeeds = funding.getFundraisingNeeds();
			fundraisingComplete = funding.getFundraisingComplete();
			fundraisingDonorAnonymous = funding.getFundraisingDonorAnonymous();
			fundraisingDonorAmount = funding.getFundraisingDonorAmount();
			fundraisingDonationIncremental = funding
					.getFundraisingDonationIncremental();
			// Tuan

			ServiceReferenceDAO srd = new ServiceReferenceDAO();

			String refCode[] = new String[] { "SBeC", "SBaC", "SDC", "SPCC",
					"CSP", "CO", "Contract Outcome", "Contract Obligation" };
			listR = srd.getListReference(refCode);
			ArrayList<String> listRefID = null;
			if (serviceid > 0) {
				listRefID = srd.getServiceReference(serviceid);
				if (listRefID == null)
					System.out.println("list ref id=null");
			}

			listCheck = new ArrayList<Checkbox>();
			Checkbox cb = null;

			for (Reference i : listR) {
				cb = new Checkbox(i, false);
				listCheck.add(cb);
			}
			if (listRefID != null) {
				for (int i = 0; i < listR.size(); i++) {
					for (String j : listRefID) {
						// System.out.println("list R refID="+listR.get(i).getRefID());
						// System.out.println("listRefID="+j);
						if (listR.get(i).getRefID().equals(j)) {
							System.out.println(j + " equal");
							listCheck.get(i).setChecked(true);
							System.out.println("check: "
									+ listCheck.get(i).isChecked());
						}
					}
				}
			}
		}
		
		ConnectDB con = new ConnectDB();
		listOrg = con.getListOrganizationsActive();
		listPremise = con.getListPremise(id);
		return SUCCESS;
	}

	public String active() {
		int kq = Dao_addService.active(sv_name);
		if (kq > -1) {
			System.out.println("sv :" + sv_name);
			sv = Dao_addService.getServices(sv_name);
			Dao_addService dao = new Dao_addService();
			listAttend = dao.getList("sv_att");
			listServiceType = dao.getList("sv_type");
			listMethod = dao.getList("sv_method");
			if (sv != null) {
				id = sv.getId();
				sub_type = sv.getSub_type();
				contacts = sv.getContact();
				serviceDescription = sv.getSv_description();
				System.out.println("des : " + serviceDescription);
				client_des = sv.getClient_des();
				sv_attenace = sv.getSv_attenace();
				sv_start_expect = sv.getSv_start_expect();
				sv_start = sv.getSv_start();
				sv_end = sv.getSv_end();
				sv_ed_year = sv.getSv_ed_year();
				sv_ed_month = sv.getSv_ed_month();
				if (sv_ed_month > 0 || sv_ed_year > 0)
					sv_ed = "yes";
				else
					sv_ed = "no";
				active = sv.isActive();
				if (active)
					actives = "yes";
				else
					actives = "no";
				sv_full_des = sv.getSv_full_des();
				dept_code = sv.getDept_code();
				sv_type = sv.getSv_type();
				sv_des_delivery = sv.getSv_des_delivery();
				sv_contract_code = sv.getSv_contract_code();
				sv_contract_value = sv.getSv_contract_value();
				contract_state = sv.isContract_state();
				if (contract_state)
					sv_state = "true";

				else
					sv_state = "false";
				System.out.println("state :" + sv_state);
				method = sv.getMethod();

				// Tuan
				serviceid = id;
				ServiceReferenceDAO srd = new ServiceReferenceDAO();

				String refCode[] = new String[] { "SBeC", "SBaC", "SDC",
						"SPCC", "CSP", "CO", "Contract Outcome",
						"Contract Obligation" };
				listR = srd.getListReference(refCode);
				ArrayList<String> listRefID = null;
				if (serviceid > 0) {
					listRefID = srd.getServiceReference(serviceid);
					if (listRefID == null)
						System.out.println("list ref id=null");
				}

				listCheck = new ArrayList<Checkbox>();
				Checkbox cb = null;

				for (Reference i : listR) {
					cb = new Checkbox(i, false);
					listCheck.add(cb);
				}
				if (listRefID != null) {
					for (int i = 0; i < listR.size(); i++) {
						for (String j : listRefID) {
							// System.out.println("list R refID="+listR.get(i).getRefID());
							// System.out.println("listRefID="+j);
							if (listR.get(i).getRefID().equals(j)) {
								System.out.println(j + " equal");
								listCheck.get(i).setChecked(true);
								System.out.println("check: "
										+ listCheck.get(i).isChecked());
							}
						}
					}
				}
			}
			return SUCCESS;
		} else
			return ERROR;
	}

	private ArrayList<Services> list;

	public ArrayList<Services> getList() {
		return list;
	}

	public void setList(ArrayList<Services> list) {
		this.list = list;
	}

	// --------
	public String amendServicẹ() {
		if (actives.equals("yes"))
			active = true;
		else
			active = false;
		contract_state = Boolean.parseBoolean(sv_state);
		Services temp = Dao_addService.getServices(sv_name);
		id = temp.getId();
		int kq = Dao_addService.updateService(id, sv_name, sub_type, contacts,
				serviceDescription, client_des, sv_attenace, sv_start_expect,
				sv_start, sv_end, sv_ed_year, sv_ed_month, active, sv_full_des,
				dept_code, sv_type, sv_des_delivery, sv_contract_code,
				sv_contract_value, contract_state, method);
		if (kq > -1) {
			System.out.println("selectedid=" + selectedid);
			String refID[] = selectedid.split(" ");
			if (refID != null && refID.length > 0) {
				ServiceReferenceDAO srd = new ServiceReferenceDAO();
				srd.saveServiceReference(id, refID);
			}
			

			// Tuyen
			// tuyen
			if (sub_type.equals("Funding")) {
				if (!contact2.equals("") && fundingAmount != 0) {
					DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
					try {
						start = df.parse(fundingStart);
						sqlstart = new java.sql.Date(start.getTime());
						end = df.parse(fundingEnd);
						sqlend = new java.sql.Date(end.getTime());
						requiredby = df.parse(fundraisingRequiredBy);
						sqlrequiredby = new java.sql.Date(requiredby.getTime());
						completeddate = df.parse(fundraisingCompletedDate);
						sqlcompleteddate = new java.sql.Date(
								completeddate.getTime());
						donationdate = df.parse(fundraisingDonationDate);
						sqldonationdate = new java.sql.Date(
								donationdate.getTime());
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					ConDB con = new ConDB();
					serviceid = id;
					con.deleteFunding(serviceid);
					con.saveFunding(new Funding(
							fundingId,
							serviceid,
							fundingSource,
							contact2,
							// fundingcontact2Details,
							fundingAmount, sqlstart, sqlend, fundingNeeds,
							fundingContinuationNeeded,
							fundingContinuationAmount,
							fundingContinuationDetails, fundraisingForText,
							fundraisingWhy, fundraisingNeeds, sqlrequiredby,
							fundraisingComplete, sqlcompleteddate,
							fundraisingDonorAnonymous, fundraisingDonorAmount,
							sqldonationdate, fundraisingDonationIncremental));

				}
			}
			list = Dao_addService.getList();
			System.out.println("Cap nhat thanh cong");
			return SUCCESS;
		} else
			return ERROR;
	}

	// ---copy
	private int index;

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String copyService() {
		list = Dao_addService.getList();
		sv = list.get(index);
		Dao_addService dao = new Dao_addService();
		listAttend = dao.getList("sv_att");
		listServiceType = dao.getList("sv_type");
		listMethod = dao.getList("sv_method");
		if (sv != null) {
			id = sv.getId();
			sub_type = sv.getSub_type();
			contacts = sv.getContact();
			serviceDescription = sv.getSv_description();
			System.out.println("des : " + serviceDescription);
			client_des = sv.getClient_des();
			sv_attenace = sv.getSv_attenace();
			sv_start_expect = sv.getSv_start_expect();
			sv_start = sv.getSv_start();
			sv_end = sv.getSv_end();
			sv_ed_year = sv.getSv_ed_year();
			sv_ed_month = sv.getSv_ed_month();
			if (sv_ed_month > 0 || sv_ed_year > 0)
				sv_ed = "yes";
			else
				sv_ed = "no";
			active = sv.isActive();
			if (active)
				actives = "yes";
			else
				actives = "no";
			sv_full_des = sv.getSv_full_des();
			dept_code = sv.getDept_code();
			sv_type = sv.getSv_type();
			sv_des_delivery = sv.getSv_des_delivery();
			sv_contract_code = sv.getSv_contract_code();
			sv_contract_value = sv.getSv_contract_value();
			contract_state = sv.isContract_state();
			if (contract_state)
				sv_state = "true";

			else
				sv_state = "false";
			method = sv.getMethod();

			// Tuan
			serviceid = id;
			ServiceReferenceDAO srd = new ServiceReferenceDAO();

			String refCode[] = new String[] { "SBeC", "SBaC", "SDC", "SPCC",
					"CSP", "CO", "Contract Outcome", "Contract Obligation" };
			listR = srd.getListReference(refCode);
			ArrayList<String> listRefID = null;
			if (serviceid > 0) {
				listRefID = srd.getServiceReference(serviceid);
				if (listRefID == null)
					System.out.println("list ref id=null");
			}

			listCheck = new ArrayList<Checkbox>();
			Checkbox cb = null;

			for (Reference i : listR) {
				cb = new Checkbox(i, false);
				listCheck.add(cb);
			}
			if (listRefID != null) {
				for (int i = 0; i < listR.size(); i++) {
					for (String j : listRefID) {
						// System.out.println("list R refID="+listR.get(i).getRefID());
						// System.out.println("listRefID="+j);
						if (listR.get(i).getRefID().equals(j)) {
							System.out.println(j + " equal");
							listCheck.get(i).setChecked(true);
							System.out.println("check: "
									+ listCheck.get(i).isChecked());
						}
					}
				}
			}
		}
		return SUCCESS;
	}
}
